package cj.web.marriage.controllers;

import java.util.List;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import cj.web.admin.constants.MemuEnum;
import cj.web.login.controllers.BaseController;
import cj.web.marriage.dao.VoteDAO;
import cj.web.marriage.dao.VoteResultsDAO;
import cj.web.marriage.domain.Vote;
import cj.web.marriage.domain.VoteResults;

@Path("/voteResults")
public class VoteResultsController extends BaseController{

	private static Logger logger = Logger.getLogger(VoteResultsController.class.getName());
	
	@Autowired
	private VoteResultsDAO voteResultsDao;
	@Autowired
	private VoteDAO voteDao;
	
	@Get("show")
	public String show(Model model,VoteResults voteResults) {
		//MemuEnum
        model.add("MemuEnum",MemuEnum.voteResult);
        List<Vote> objlis = voteDao.queryAll();
        model.add("objlis",objlis);
		return "/views/marriage/voteResultList.vm";
	}

	@Post("getList")
	public String queryList(VoteResults voteResults) {
		JSONObject jo = new JSONObject();
		List<VoteResults> objs = voteResultsDao.query(voteResults);
		int size = voteResultsDao.querySize(voteResults);
		jo.put("data", objs);
		jo.put("draw", voteResults.getDraw());
		jo.put("recordsTotal", size);
		jo.put("recordsFiltered", size);
		
		return "@"+jo.toString();
	}
	
	@Get("deleteByVoteId")
	public String deleteById(Model model,@Param("voteId") int voteId){
		voteResultsDao.deleteByVoteId(voteId);
		return "r:show";
	}
}